/*
 * HoraData.java
 *
 * Created on 21 de Setembro de 2006, 10:40
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */
package br.com.frigofish.control;

import java.awt.print.PrinterException;
import java.awt.print.PrinterJob;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import javax.print.DocFlavor;

import javax.print.PrintService;
import javax.print.PrintServiceLookup;
import javax.print.StreamPrintServiceFactory;
import javax.print.attribute.HashPrintRequestAttributeSet;
import javax.print.attribute.PrintRequestAttributeSet;
import javax.print.attribute.PrintServiceAttributeSet;

/**
 *
 * @author Rogerio Tomassoni
 */
public class ConexaoImpressora {
    private File m_path;
    private String impressora;
    private PrintWriter m_outStream;
    
    /**
     * @param args
     */
    
    
    public void open() throws Exception {
        m_path = new File(impressora);
        FileOutputStream fileStream = new FileOutputStream(m_path);
        if (m_outStream != null) {
            close();
        }
        m_outStream = new PrintWriter(fileStream);
    }
    
    public void close() throws IOException {
        if (m_outStream != null) {
            m_outStream.close();
            m_outStream = null;
        }
    }
    
    public void writeZplScript(String stScript) {
        if (m_outStream != null){
            m_outStream.write(stScript);
            m_outStream.flush();
        } 
    }
    
    public PrintService[] listarImpressoras(){
        PrintService[] services = PrintServiceLookup.lookupPrintServices(null,null);
        return services;
    }
    
    public void setImpressora(String p_impressora) {
        this.impressora = p_impressora;
    }
    
    
}
